package com.spring.sunflower.bottompanel;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.spring.sunflower.R;
import com.spring.sunflower.base.AppBaseFragment;
import com.spring.sunflower.conversation.EmotionVerticalAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Kevin<br/>
 * Description:表情
 */
public class EmotionVerticalFragment extends AppBaseFragment {
    private int emotion_map_type;
    private RecyclerView recyclerView;
    private EmotionVerticalAdapter mAdapter;
    private List<String> emotionNameData = new ArrayList<>();
    private LinearLayout llDelete;
    private EditText mEditText;

    public EmotionVerticalFragment(EditText editText) {
        mEditText = editText;
    }

    /**
     * 创建与Fragment对象关联的View视图时调用
     *
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_emotion_vertical, container, false);
        recyclerView = rootView.findViewById(R.id.rvRecyclerViewEmotion);
        llDelete = rootView.findViewById(R.id.llDelete);
        emotion_map_type = EmotionUtils.EMOTION_CLASSIC_TYPE;
        for (String emojiName : EmotionUtils.getEmojiMapX(emotion_map_type).keySet()) {
            emotionNameData.add(emojiName);
        }
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mActivity, 7);
        recyclerView.setLayoutManager(gridLayoutManager);
        mAdapter = new EmotionVerticalAdapter(mActivity, emotionNameData);
        recyclerView.setAdapter(mAdapter);
        llDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(mEditText.getText().toString().trim())) return;
                mEditText.dispatchKeyEvent(new KeyEvent(
                        KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
        });
        return rootView;
    }


}
